package com.googlecode.horncomb.web.spring.mvc.support;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.util.StringUtils;
import org.springframework.validation.BindException;

import com.googlecode.horncomb.web.spring.mvc.EventViewResolver;

public class MappedEventViewResolver implements EventViewResolver {

	private Map<String, String> eventViewMap = null;

	@SuppressWarnings("unchecked")
	public Object getView(HttpServletRequest request, Object command,
			BindException errors, Map controlModel, String event) {
		if (this.eventViewMap != null) {
			String viewName = this.eventViewMap.get(event);
			if (StringUtils.hasText(viewName)) {
				return viewName;
			}
		}
		return null;
	}

	/**
	 * @param eventViewMap
	 *            the eventViewMap to set
	 */
	public void setEventViewMap(Map<String, String> eventViewMap) {
		this.eventViewMap = eventViewMap;
	}
}
